function input_keyup(type) {//keyup不能是数字
	var val = $("#"+type).val();
	if(isNaN(val)){
		$("#"+type).val(0);
	}
}

function check_phone(){//验证手机号
	var tel   = $("#tel").val();
	var check = /^(13|15|18)[0-9]{9}$/;
	$("#span_tel").text("");
	if(!check.exec(tel)){
		$("#span_tel").text("请输入手机号");
		$("#tel").val("");
	}
}
function check_username(typeid,url){//查询用户名是否可以使用
	var typeVal= $("#"+typeid).val();
	var span    = $("#span_"+typeid);
	span.text("");
	if(typeVal!=""){
		$.post(url,{type:typeVal},function(data){
			if(data.status==1){
				span.text(data.message);
				span.css("color","green");
			}else{
				span.text(data.message);
				span.css("color","red");
			}
		},'json');
	}else{
		span.text("请输入,不能为空");
	}
}
function is_exist(id){//判断是否存在
	var value = $("#"+id).val();
	if(value!=''){
		$("#span_"+id).text("");
		return true;
	}else{
		$("#span_"+id).text("不能为空");
		$("#span_"+id).css("color","red");
		return false;
	}
}
function check_takeout()
{//验证外卖表单
	var sel  = $("#takeoutCateId").val();
	var name = $("#takeoutName").val();
	var price= $("#takeoutPrice").val();
	var pic  = $("#shoppic").val();
	if(sel==""||sel==null)
	{
		$("#span_takeoutCateId").text("暂无分类,请先添加分类");
		$("#span_takeoutCateId").css("color","red");
		return false;
	}
	if(name=="")
	{
		$("#span_takeoutName").text("商品名称不能为空");
		$("#span_takeoutName").css("color","red");
		return false;
	}
	if(price==""||price==0)
	{
		$("#span_takeoutPrice").text("商品价格不能为空");
		$("#span_takeoutPrice").css("color","red");
		$("#takeoutPrice").val("");
		return false;
	}	
	if(pic=="")
	{
		$(".upload_file").text("未上传图片");
		$(".upload_file").css("color","red");
		setTimeout("$('.upload_file').text('')",5000);
		return false;
	}
}
function check_slide()
{//验证幻灯片
	var pic = $("#shoppic").val();
	if(pic=="")
	{
		$(".upload_file").text("未上传图片");
		$("#upload_file").css("color","red");
		setTimeout("$('.upload_file').text('')",5000);
		return false;
	}
}
function check_shop(){//验证商家表单
	var username= $("#shopUserName").val();
	var pass    = $("#shopPassWord").val();
	var tel     = $("#tel").val();
	var pic     = $("#shoppic").val();
	var shopname= $("#shopName").val();
	var address = $("#shopAddress").val();
	if(username=="")
	{
		$("#span_shopUserName").text("请输入商家用户名");
		$("#span_shopUserName").css("color","red");
		return false;
	}

	if(pass=="")
	{
		$("#span_shopPassWord").text("请输入商家密码");
		$("#span_shopPassWord").css("color","red");
		return false;
	}

	if(tel=="")
	{
		$("#span_tel").text("请输入商家电话");
		$("#span_tel").css("color","red");
		return false;
	}

	if(shopname=="")
	{
		$("#span_shopName").text("请输入商家名称");
		$("#span_shopName").css("color","red");
		return false;
	}

	if(address=="")
	{
		$("#span_shopAddress").text("请输入商家地址");
		$("#span_shopAddress").css("color","red");
		return false;
	}

	if(pic=="")
	{
		$(".upload_file").text("未上传图片");
		$(".upload_file").css("color","red");
		setTimeout("$('.upload_file').text('')",5000);
		return false;
	}

}
function del_text(type){//清楚提示消息
	var val = $("#"+type).val();
	if(val!=""){
		$("#span_"+type).text("");
	}
}
function check_gift()
{
	var name = $("#giftName").val();
	var point= $("#askIntegral").val();
	var pic  = $("#shoppic").val();
	if(name=="")
	{
		$("#span_giftName").text("请输入名称");
		$("#span_giftName").css("color","red");
		return false;
	}

	if(point==""||point==0)
	{
		$("#span_askIntegral").text("请输入所需金币");
		$("#span_askIntegral").css("color","red");
		$("#askIntegral").val("");
		return false;
	}

	if(pic=="")
	{
		$(".upload_file").text("未上传图片");
		$(".upload_file").css("color","red");
		setTimeout("$('.upload_file').text('')",5000);
		return false;
	}

}

function ajax_upload(action_url,del_url,showpic,file,i,bbb)
{
	var percent     = $('#percent'+i);
    var percent_pic = $('#percent_pic'+i);
    var btn         = $("#upload_file"+i);
    $("#"+file+i).wrap("<form id='myupload"+i+"' action='"+action_url+"' method='post' enctype='multipart/form-data'></form>");
    $("#"+file+i).change(function(){
    	$("#myupload"+i).ajaxSubmit({
	        dataType:  'json',
	        beforeSend: function() {
	            percent.show();
	            percent_pic.show();
	            var percentVal = '0%';
	            percent.html(percentVal);
	            btn.html("上传中...");
	        },
	        uploadProgress: function(event, position, total, percentComplete) {
	            var percentVal = percentComplete + '%';
	            percent.html(percentVal);
	        },
	        success: function(data) {
	        	var show_pic = $("#"+showpic+i).val();
	        	if(show_pic!=""){
	        		$.post(del_url,{pic:show_pic},function(data){
	        		},'json');
	        	}
	        	if(data.pic!="")
	            {
	                $("#"+showpic+i).val(data.pic);
					$("#"+bbb+i).attr('src',data.pic_path);
					$("#"+bbb+i).show();
	                btn.text("上传成功");
	                btn.css("color","green");
	            }
	            else
	            {
	                percent.hide();
	                btn.text(data.name);
	                btn.css("color","red");
	            }
	        },
	        error:function(xhr){
	            btn.html("上传失败");
	            btn.css("color","red");
	        }
		});
    });
    
}
function ajax_upload_sender(action_url,del_url,showpic,file,i,tx,src_tx)
{
	var percent     = $('#percent'+i);
    var percent_pic = $('#percent_pic'+i);
    var btn         = $("#upload_file"+i);
    $("#"+file+i).wrap("<form id='myupload"+i+"' action='"+action_url+"' method='post' enctype='multipart/form-data'></form>");
    $("#"+file+i).change(function(){
    	$("#myupload"+i).ajaxSubmit({
	        dataType:  'json',
	        beforeSend: function() {
	            percent.show();
	            percent_pic.show();
	            var percentVal = '0%';
	            percent.html(percentVal);
	            btn.html("上传中...");
	        },
	        uploadProgress: function(event, position, total, percentComplete) {
	            var percentVal = percentComplete + '%';
	            percent.html(percentVal);
	        },
	        success: function(data) {
	        	var show_pic = $("#"+showpic+i).val();
	        	if(show_pic!=""){
	        		$.post(del_url,{pic:show_pic},function(data){
	        		},'json');
	        	}
	        	if(data.pic!="")
	            {
	                $("#"+showpic+i).val(data.pic);
					document.getElementById(tx).src=src_tx+data.pic;
	                btn.text("上传成功");
	                btn.css("color","green");
	            }
	            else
	            {
	                percent.hide();
	                btn.text(data.name);
	                btn.css("color","red");
	            }
	        },
	        error:function(xhr){
	            btn.html("上传失败");
	            btn.css("color","red");
	        }
		});
    });
    
}
function ajax_upload_two(action_url,del_url,showpic,file,i)
{
	var percent     = $('#percent_two'+i);
    var percent_pic = $('#percent_pic_two'+i);
    var btn         = $("#upload_file_two"+i);
    $("#"+file+i).wrap("<form id='myupload_two"+i+"' action='"+action_url+"' method='post' enctype='multipart/form-data'></form>");
    $("#"+file+i).change(function(){
    	$("#myupload_two"+i).ajaxSubmit({
	        dataType:  'json',
	        beforeSend: function() {
	            percent.show();
	            percent_pic.show();
	            var percentVal = '0%';
	            percent.html(percentVal);
	            btn.html("上传中...");
	        },
	        uploadProgress: function(event, position, total, percentComplete) {
	            var percentVal = percentComplete + '%';
	            percent.html(percentVal);
	        },
	        success: function(data) {
	        	var show_pic = $("#"+showpic+i).val();
	        	if(show_pic!=""){
	        		$.post(del_url,{pic:show_pic},function(data){
	        		},'json');
	        	}
	        	if(data.pic!="")
	            {
	                $("#"+showpic+i).val(data.pic);
	                btn.text("上传成功");
	                btn.css("color","green");
	            }
	            else
	            {
	                percent.hide();
	                btn.text(data.name);
	                btn.css("color","red");
	            }
	        },
	        error:function(xhr){
	            btn.html("上传失败");
	            btn.css("color","red");
	        }
		});
    });
    
}
